package gapidt.plugin;

import gapidt.plugin.views.AnalysisResultsView;

import org.apache.log4j.Logger;
import org.eclipse.core.internal.resources.Workspace;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;


public class WorkbenchUtils {
	
	static Logger logger = Logger.getLogger(WorkbenchUtils.class.getName());
	
	public static void showView(String viewId){
		IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		try {
			activePage.showView(viewId);
		} catch (PartInitException e) {
			e.printStackTrace();
		}
	}
	
	public static IViewPart getView(String viewId){
		IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		if(activePage != null){
			return activePage.findView(viewId);
		}
		return null;
	}
	
	public static void showErrorMessage(String title, String message) {
		
		final String pTitle = title;
		final String pMessage = message;
		
		Display.getDefault().asyncExec(new Runnable() {
		    @Override
		    public void run() {
		        IWorkbenchWindow iw = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		        MessageDialog.openError(
		        		iw.getShell(),
		    			pTitle,
		    			pMessage);
		    }
		});
		
	}
}
